package org.smile.homework01.paladin.rocket;

public class Rockets {
    String name;
    Engines[] engineList;

    public Rockets(int cnt){
        engineList = new Engines[cnt];
        for(int i = 0; i < cnt; i++) {
            engineList[i] = new Engines(i+1);
        }
    }

    public void engineCheck(){
        for(int i = 0; i < engineList.length; i++) {
            System.out.println(engineList[i].name+engineList[i].status);
            System.out.println("可运行时间为：" + engineList[i].getRunningTime());
            System.out.println("冷却时间为：" + engineList[i].getRunningTime());

        }
        System.out.println();
        System.out.println("飞船状态检查完毕");
        System.out.println();
        System.out.println();
    }

    public void lunch(){
        int startEngine = 0;
        do {

            int runningTime = engineList[startEngine].getRunningTime();
            int cdTime = engineList[startEngine].getRunningTime();
            String engineName = engineList[startEngine].name;
            String engineStatus = engineList[startEngine].getStatus();
            if(!engineStatus.equals("待命")){
                System.out.println(engineName + "引擎未就绪,飞行结束");
                break;
            }
            System.out.println(engineName + "开始运行");
            while(true) {
                for(Engines i: engineList){
                    i.coldDown();
                }
                runningTime--;
                System.out.println(engineName + "运行时间剩余" + runningTime + "秒");
                if(runningTime <= 0){
                    System.out.println(engineList[startEngine].name + "运行完成进入冷却");
                    engineList[startEngine].setCding(cdTime);
                    engineList[startEngine].status = "冷却中";
                    break;
                }
            }
            startEngine++;
            if(startEngine == engineList.length){
                startEngine = 0;
            }
        }while (startEngine < engineList.length);
    }

}
